let app = getApp()
Component({
    properties: {
      address:{type:String},
      mode:{type:String},
      themeColor:{type:String},
      selectList:{
         type: Object,
          observer: function(newVal, oldVal) {
            this.update()
          }
      }
      },
      data:{
        itemHeight:'height:88rpx',
        pickVal:[0,0,0]
      },
    lifetimes: {
        attached: function () {
          var that=this
          var mode=this.data.mode
          if(mode=='region'){
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Member_getArea'
            },
            success: function(res) {
              console.log(res.data)
              that.setData({
                provinces:res.data.data
              })
            }
          })
          }
         }
      },
    methods: {
      sure:function(){
         var choose=[];
         choose['area']=this.data.area;
         choose['address']=this.data.address;
         choose['pickVal']=this.data.pickVal;
         this.triggerEvent ('choose',choose)
         this.setData({
          showPicker:false,
          selectList:[]
        })
      },
      cityChange:function(e){
        var provinces=this.data.provinces
        var p=e.detail.value[0]
        var c=e.detail.value[1]
        var area=e.detail.value[2]
        this.setData({
          citys:provinces[p].children,
          areas:provinces[p].children[c].children,
          pickVal:[e.detail.value[0],e.detail.value[1],e.detail.value[2]],
          area:provinces[p].children[c].children[area].value,
          address:provinces[p].label+' '+provinces[p].children[c].label+' '+provinces[p].children[c].children[area].label
        })
      },
      cancel:function(){
        this.setData({
          showPicker:false,
          selectList:[]
        })
      },
      update:function(){
        var data=this.data.selectList
        if(data!='')
        {
          if(this.data.address=='')
          {
            this.setData({
            address:data.data[0].label+data.data[0].children[0].label+data.data[0].children[0].children[0].label
            })
          }
          this.setData({
            showPicker:true,
            provinces:data.data,
            citys:data.data[0].children,
            areas:data.data[0].children[0].children,
            area:data.data[0].children[0].children[0].value,
           })
        }
      }
    }
});
